<script setup>
// TODO: 编辑
import { ref } from 'vue'

import axios from 'axios'

let emit = defineEmits(['changeF'])

let data = ref({})


let change = () => {
  axios.patch(`/edit/${data.value.id}`, {
    name: data.value.name,
    place: data.value.place
  }).then((res) => {
    dialogVisible.value = false
    data.value = {}
    alert('修改成功！')
    emit('changeF')
  }).catch(err => {
    console.log(err)
  })
}



// 弹框开关
const dialogVisible = ref(false)

let changeDV = (res) => {
  data.value = res
  dialogVisible.value = !dialogVisible.value
}

defineExpose({
  changeDV
})


</script>

<template>
  <el-dialog v-model="dialogVisible" title="编辑" width="400px">
    <el-form label-width="50px">
      <el-form-item label="姓名">
        <el-input v-model="data.name" placeholder="请输入姓名" />
      </el-form-item>
      <el-form-item label="籍贯">
        <el-input v-model="data.place" placeholder="请输入籍贯" />
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="dialogVisible = false">取消</el-button>
        <el-button type="primary" @click="change">确认</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<style scoped>
.el-input {
  width: 290px;
}
</style>
